<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/2/20
 * Time: 11:29
 */
namespace app\admin\controller;


use think\Db;
use think\Request;
class Evaluate extends Base {
    /**
     * 列表展示
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax()){
            $where = [];
            $user_name = trim(input('user_name'), ' ');
            $comment_see = trim(input('comment_see'), ' ');
            $comment_god = trim(input('comment_god'), ' ');
            if(isset($user_name) && $user_name != ''){
                $where['user_username|comment_content|h_content'] = ['like', '%' . $user_name . '%'];
            }
            if(isset($comment_see) && $comment_see != ''){
                $where['comment_see'] = $comment_see;
            }
            if(isset($comment_god) && $comment_god != ''){
                $where['comment_god'] = $comment_god;
            }
            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_comment')
                ->join('up_hot', 'h_id = comment_hot_id', 'left')
                ->join('up_u_user', 'user_id = comment_reply_user_id', 'left')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::table('up_comment c')
                ->join('up_hot', 'h_id = comment_hot_id', 'left')
                ->join('up_u_user', 'user_id = comment_reply_user_id', 'left')
                ->field('c.*, user_username, h_content')
                ->where($where)
                ->page($NowPage,$limits)
                ->order('comment_time desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
}